-- 顺序执行队列

local SimpleTaskQueue = class("SimpleTaskQueue")
local TaskItem = require("app.common.TaskItem")

function SimpleTaskQueue:ctor()
	self:reset()
end

function SimpleTaskQueue:reset()
	self._taskQueue = {}
	self._curHandleTask = nil
end

function SimpleTaskQueue:appendTaskItem( taskItem )
	if self._taskQueue and taskItem then
		self._taskQueue[#self._taskQueue+1] = taskItem
	
		taskItem:setQueue(self)
	end
	self:continue()
end

function SimpleTaskQueue:appendTask( ... )
	local taskItem = TaskItem.new(...)
	self:appendTaskItem(taskItem)
end

function SimpleTaskQueue:startOneTask()
	if not self._curHandleTask then
		self._curHandleTask = self._taskQueue and table.remove(self._taskQueue,1)
		if self._curHandleTask then
			self._curHandleTask:start()
		end
		return true
	end
	return false
end

function SimpleTaskQueue:finishOneTask()
	if self._curHandleTask then
		self._curHandleTask:finish()
		self._curHandleTask = nil
		return true
	end
	return false
end

function SimpleTaskQueue:continue()
	self:startOneTask()
end

function SimpleTaskQueue:nextOne()
	self._curHandleTask = nil
	self:continue()
end

return SimpleTaskQueue